<template>
    <div>
      <section id="player">
      <header class="header">
        <h1>
          <a href="http://www.itheima.com/">
            <img src="../../assets/img/black.png" alt="" />
          </a>
          小黑播放器
        </h1>
        <!-- 输入框 -->
        <input
          v-model="inputValue"
          @keyup.enter="search"
          placeholder="请输入歌名"
          class="new-todo"
        />
      </header>
      <!-- 列表区域 -->
      <section class="main">
        <ul class="music-list">
          <li v-for="(item,index) in results" :key="index" class="music">
            <div class="view">
              <span class="index">{{ index+1 }}.</span>
              <label>{{ item.name }}</label>
              <!-- 播放按钮 -->
              <button @click="play(item.id)" class="play"></button>
            </div>
          </li>
        </ul>
      </section>
      <!-- 音频标签 -->
      <footer class="footer">
        <!-- autoplay 自动播放 -->
        <audio :src="url"  autoplay controls></audio>
      </footer>
    </section>
    </div>
</template>

<script>
import {getplayMultidata,getsearchMultidata} from '../../axios/play'
export default {
    name: 'VuePlay',
    data() {
        return {
            inputValue:'',
            url:'',
            results:[]
        };
    },

    methods: {
        search(){
            getsearchMultidata(this.inputValue).then(res=>{
                this.results = res.result.songs
                // console.log(res);
            })
        },
        play(id){
             getplayMultidata(id).then(res=>{
                //  console.log(res);
                 this.url = res.data[0].url
             })
        
        }
    },
};
</script>

<style lang="scss" scoped>
body {
  margin: 0;
  padding: 0;
}
button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: 100%;
  vertical-align: baseline;
  font-family: inherit;
  font-weight: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: #f5f5f5;
}
a{
  text-decoration: none;
}
:focus {
  outline: 0;
}

.hidden {
  display: none;
}

#player {
  background: #fff;
  min-width: 230px;
  max-width: 550px;
  margin: 160px auto;
  position: relative;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}

#player input::-webkit-input-placeholder {
  font-style: italic;
  font-weight: 300;
  color: #e6e6e6;
}

#player input::-moz-placeholder {
  font-style: italic;
  font-weight: 300;
  color: #e6e6e6;
}

#player input::input-placeholder {
  font-style: italic;
  font-weight: 300;
  color: gray;
}

#player h1 {
  position: absolute;
  top: -160px;
  width: 100%;
  font-size: 60px;
  font-weight: 100;
  text-align: center;
  color: rgba(175, 47, 47, 0.8);
  -webkit-text-rendering: optimizeLegibility;
  -moz-text-rendering: optimizeLegibility;
  text-rendering: optimizeLegibility;
}

.new-todo,
.edit {
  position: relative;
  margin: 0;
  width: 100%;
  font-size: 24px;
  font-family: inherit;
  font-weight: inherit;
  line-height: 1.4em;
  border: 0;
  color: inherit;
  padding: 6px;
  border: 1px solid #999;
  box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.new-todo {
  padding: 16px;
  border: none;
  background: rgba(0, 0, 0, 0.003);
  box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
}

.main {
  position: relative;
  z-index: 2;
  border-top: 1px solid #e6e6e6;
}

.toggle-all {
  width: 1px;
  height: 1px;
  border: none; /* Mobile Safari */
  opacity: 0;
  position: absolute;
  right: 100%;
  bottom: 100%;
}

.toggle-all + label {
  width: 60px;
  height: 34px;
  font-size: 0;
  position: absolute;
  top: -52px;
  left: -13px;
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
}

.toggle-all + label:before {
  content: '❯';
  font-size: 22px;
  color: #e6e6e6;
  padding: 10px 27px 10px 27px;
}

.toggle-all:checked + label:before {
  color: #737373;
}

.music-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 420px;
  overflow: auto;
}

.music-list li {
  position: relative;
  font-size: 24px;
  border-bottom: 1px solid #ededed;
  height: 60px;
  box-sizing: border-box;
}
.music-list li:hover {
  background-color: #f6f7fa;
}


.music-list li:last-child {
  border-bottom: none;
}
.music-list li .view {
  height: 100%;
}

.music-list .view .index {
  position: absolute;
  color: gray;
  left: 10px;
  top: 20px;
  font-size: 16px;
}

.music-list li .toggle {
  text-align: center;
  width: 40px;
  /* auto, since non-WebKit browsers doesn't support input styling */
  height: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: auto 0;
  border: none; /* Mobile Safari */
  -webkit-appearance: none;
  appearance: none;
}

.music-list li .toggle {
  opacity: 0;
}

.music-list li label {
  font-size:15px;
  word-break: break-all;
  padding: 20px 15px 15px 60px;
  display: block;
  line-height: 1;
  transition: color 0.4s;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.music-list li.completed label {
  color: #d9d9d9;
  text-decoration: line-through;
}

.music-list li .play {
  display: none;
  position: absolute;
  top: 0;
  right: 10px;
  bottom: 0;
  width: 40px;
  height: 40px;
  margin: auto 0;
  font-size: 30px;
  color: #cc9a9a;
  margin-bottom: 11px;
  transition: color 0.2s ease-out;
}

.music-list li .play:hover {
  color: #af5b5e;
}
.music-list li .play:hover:after {
  border-color: #af5b5e;
}

.music-list li .play:after {
  display: inline-block;
  content: '△';
  border: 2px solid #cc9a9a;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  line-height: 30px;
  text-align: center;
  transform: rotate(90deg);
  cursor: pointer;
}

.music-list li:hover .play {
  display: block;
}

.footer {
  color: #777;
  text-align: center;
  border-top: 1px solid #e6e6e6;
  background-color: #f1f3f4;
}

.footer:before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 50px;
  overflow: hidden;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
    0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
    0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
.footer audio {
  width: 100%;
}

.clear-completed,
html .clear-completed:active {
  float: right;
  position: relative;
  line-height: 20px;
  text-decoration: none;
  cursor: pointer;
}

.clear-completed:hover {
  text-decoration: underline;
}

.info {
  margin: 50px auto 0;
  color: #bfbfbf;
  font-size: 15px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  text-align: center;
}

.info p {
  line-height: 1;
}

.info a {
  color: inherit;
  text-decoration: none;
  font-weight: 400;
}

.info a:hover {
  text-decoration: underline;
}

/*
	Hack to remove background from Mobile Safari.
	Can't use it globally since it destroys checkboxes in Firefox
*/
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .toggle-all,
  .music-list li .toggle {
    background: none;
  }

  .music-list li .toggle {
    height: 40px;
  }
}

@media (max-width: 430px) {
  .footer {
    height: 50px;
  }

  .filters {
    bottom: 10px;
  }
}

</style>